package servlets;

import java.io.IOException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;

public class googleUserServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException {
    	UserService userService = UserServiceFactory.getUserService();
    	
        String thisURL = request.getQueryString();
        if (request.getUserPrincipal() != null) {
        	appManager.getInstance().addUsertoDB(request.getUserPrincipal().getName(),null,null);
        	response.sendRedirect(thisURL);
        } else {
            response.sendRedirect(userService.createLoginURL("/googleuserservlet?"+thisURL));
        }
    }
}